package gold.digger;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC264 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {

        public int[] arr = new int[1690];

        {
            arr[0] = 1;
            int i2 = 0, i3 = 0, i5 = 0;
            for (int i = 1; i < 1690; i++) {
                int ugly = Math.min(5 * arr[i5], Math.min(2 * arr[i2], 3 * arr[i3]));
                arr[i] = ugly;

                if (ugly == arr[i2] * 2) ++i2;
                if (ugly == arr[i3] * 3) ++i3;
                if (ugly == arr[i5] * 5) ++i5;

            }
        }

        public int nthUglyNumber(int n) {
            return arr[n - 1];
        }
    }

    public void run() {
        Solution solution = new Solution();
        List<Integer> list = new ArrayList<>();
        System.out.println(solution.toString());
    }

    public static void main(String[] args) throws Exception {
        LC264 an = new LC264();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
